/*
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-04-29 13:32:49
 */
// 引入模块
const express=require('express');
const expressSession=require('express-session');
const ejs=require('ejs')
const mongoose=require('mongoose');
const verifyLogin=require('./middlewares/verifyLogin')

// 引入数据模型
const userModel=require('./db/model/userModel')
const noteModel=require('./db/model/noteModel')

const app=express();


// 导入路由器
const pageRouter=require('./routes/pageRouter')

const apiRouters=require('./routes/apiRouters')
// 配置跨域
app.use(function(request, response, next){
    // access 访问进入  control 控制  allow 允许  origin 源
        response.setHeader('Access-Control-Allow-Origin', "*");  //任何页面发送请求都允许跨域请求
        response.setHeader('Access-Control-Expose-Headers', "*"); //暴露响应头信息
        next();
    });

// 配置session
app.use(expressSession({
    name:'s_id',
    secret:'0215',
    saveUninitialized:false,
    resave:true,
    cookie:{
        httpOnly:false,
        maxAge:1000*60*60*24
    }

}))

app.set('views',__dirname+"/html");
app.engine('html',ejs.renderFile);
app.use(express.static(__dirname+'/public'));
app.use(express.urlencoded({extended:false}));


app.use(pageRouter)
app.use(apiRouters)





app.listen(80,()=>{
    console.log('80服务器启动成功');
    
})
